package com.dream.common.utils.payutils.otherUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SendRedPackageUtils {

    public static void main(String[] args) {
        int[] packageNumberArr = {5, 6, 7, 8, 9, 10};
        int[] thunderNumberArr = {1, 2, 3, 4, 5, 6};
        int[] thunderValueArr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        for (int i = 0; i < 20; i++) {
            SendRedPackageBean sendRedPackageBean = sendredpackage(10, 52, packageNumberArr, thunderNumberArr, thunderValueArr, true, 2);
            System.out.println(sendRedPackageBean.toString());
        }
    }

    /**
     * @param minMoney         最小琻额
     * @param maxMoney         最大琻额
     * @param packageNumberArr 随机包数
     * @param thunderNumberArr 随机蕾数
     * @param thunderValueArr  随机蕾值
     * @param packageHasMoney  包名是否带琻额
     * @param moneyType        琻额类型  1整5，2整10，3整100，4整数
     * @return
     */
    public static SendRedPackageBean sendredpackage(double minMoney, double maxMoney, int[] packageNumberArr, int[] thunderNumberArr, int[] thunderValueArr, boolean packageHasMoney, int moneyType) {
        SendRedPackageBean sendredpackagebean = new SendRedPackageBean();
        int zhengNumber = 1;
        switch (moneyType) {
            case 1:
                zhengNumber = 5;
                break;
            case 2:
                zhengNumber = 10;
                break;
            case 3:
                zhengNumber = 100;
                break;
            case 4:
                zhengNumber = 1;
                break;
                default:
                    break;
        }
        int min = (int) (minMoney / zhengNumber);
        if (minMoney / zhengNumber > (int) (minMoney / zhengNumber)) {
            min = min + 1;
        }
        int max = (int) (maxMoney / zhengNumber);
        int random = (int) (min + Math.random() * (max - min + 1));
        double money = random * zhengNumber;
        sendredpackagebean.money = money;

        int packageNumberLength = packageNumberArr.length;
        int packageNumberIndex = (int) (Math.random() * packageNumberLength);
        sendredpackagebean.packageNumber = packageNumberArr[packageNumberIndex];

        int thunderNumberLength = thunderNumberArr.length;
        int thunderNumberIndex = (int) (Math.random() * thunderNumberLength);
        int thunderNumber = thunderNumberArr[thunderNumberIndex];

        List<Integer> wishingNumberList = new ArrayList<>();
        StringBuilder wishing = new StringBuilder();
        int thunderValueArrLength = thunderValueArr.length;
        for (int i = 0; i < thunderNumber; i++) {
            int thunder = thunderValueArr[(int) (Math.random() * thunderValueArrLength)];
            if (!wishingNumberList.contains(thunder)) {
                wishingNumberList.add(thunder);
            } else {
                i = i - 1;
            }
        }
        Collections.sort(wishingNumberList);
        for (Integer integer : wishingNumberList) {
            wishing.append(integer);
        }
        if (packageHasMoney) {
            wishing.insert(0, (int) money + "-");
        }
        sendredpackagebean.wishing = wishing.toString();
        return sendredpackagebean;
    }
}
